package cn.edu.zafu.bigdata.x.cxy;

import java.util.HashMap;

// 学生成绩管理类
public class StudentGradeManager {
    // 使用HashMap存储学生姓名和对应的成绩
    private HashMap<String, Integer> studentGrades;

    // 构造方法
    public StudentGradeManager() {
        studentGrades = new HashMap<>();
    }

    // 添加学生成绩
    public void addStudent(String name, int grade) {
        studentGrades.put(name, grade);
    }

    // 根据学生姓名获取成绩
    public int getGrade(String name) {
        // 如果学生不存在，则返回-1
        return studentGrades.getOrDefault(name, -1);
    }

    // 删除学生成绩
    public void removeStudent(String name) {
        studentGrades.remove(name);
    }
}

// 测试类
class TestStudentGradeManager {
    public static void main(String[] args) {
        // 创建学生成绩管理对象
        StudentGradeManager manager = new StudentGradeManager();

        // 添加几个学生成绩
        manager.addStudent("ZhangSan", 90);
        manager.addStudent("LiSi", 98);
        manager.addStudent("WangWu", 88);

        // 查询学生成绩
        System.out.println("ZhangSan's grade: " + manager.getGrade("ZhangSan")); // 应该输出90
        System.out.println("LiSi's grade: " + manager.getGrade("LiSi")); // 应该输出85
        System.out.println("WangWu's grade: " + manager.getGrade("WangWu")); // 应该输出88

        // 查询不存在的学生成绩
        System.out.println("HJN's grade: " + manager.getGrade("HJN")); // 应该输出-1

        // 删除学生成绩
        manager.removeStudent("Lisi");
        System.out.println("Lisi's grade after removal: " + manager.getGrade("Lisi")); // 应该输出-1
    }
}